package cn.wit.luohui.day11;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import org.junit.Test;

//源代码的编码会影响我们字符流的默认编码

//不管源代码是什么编码，我们都可以通过手动指定输入流的编码来正确的读取文件
public class DemoReader {
	@Test
	public void test() {
		// String path="‪‪E:\\毒鸡汤.txt";
		//String path = "E:\\毒鸡汤.txt";
		//E:\camp2018\camp2018\camp2018\day10\scores.csv
//		String path ="E:\\camp2018\\camp2018\\camp2018\\day10\\scores.csv";
		String path="E:\\camp2018\\camp2018\\camp2018\\day10\\scores.csv";
		try (
				InputStreamReader is = new InputStreamReader(new FileInputStream(path), "gbk")
			
			) {
			
			char[] chars = new char[1024];

			int count = 0;
			while ((count = is.read(chars)) != -1) {
				System.out.println(new String(chars, 0, count));
				
			}

		} catch (IOException e) {

			e.printStackTrace();
		}
	}
@Test
//缓冲流，专门用来读大文件
public void test3() {
	// 字节输入流
	//InputStream is=new FileInputStream("luo.txt");
	//字符流输入
	//InputStreamReader reader=new InputStreamReader(is."gbk");
	
	//缓冲流
	//BufferedReader br=new BufferedReader(reader);
	String path="E:\\camp2018\\camp2018\\camp2018\\day10\\scores.csv";
	try(
				BufferedReader br = new BufferedReader(
						new InputStreamReader(
						new FileInputStream(path), "gbk"));
			) {
			String line = null;
			while ((line = br.readLine()) != null) {
				System.out.println(line);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
}
}
